﻿using System;
using System.Collections.Generic;
using System.Text;
using System.IO;

namespace System
{
    public class IOHelper
    {
        public static void Save(string path, string info)
        {
            try
            {
                FileStream fs = new FileStream(path, FileMode.Append, FileAccess.Write);
                StreamWriter sw = new StreamWriter(fs, System.Text.UnicodeEncoding.UTF8);
                sw.Write(info);
                sw.Close();
                fs.Close();
            }
            catch
            {

            }
        }

        ///// <summary>
        ///// 保存文本
        ///// </summary>
        ///// <param name="s"></param>
        ///// <param name="Path"></param>
        //public static void Save(string s, string Path)
        //{
        //    FileStream fsobj = new FileStream(Path, FileMode.Create, FileAccess.ReadWrite);
        //    StreamWriter _sw = new StreamWriter(fsobj, System.Text.UnicodeEncoding.Default);
        //    _sw.Write(s);
        //    _sw.Close();
        //    fsobj.Close();

        //}
        /// <summary>
        /// 读取文件
        /// </summary>
        /// <param name="Path"></param>
        /// <returns>结果</returns>
        public static string Read(string Path)
        {
            if (!File.Exists(Path))
                return "";
            System.IO.FileStream fs = System.IO.File.OpenRead(Path);
            byte[] file = new Byte[fs.Length];
            fs.Read(file, 0, Convert.ToInt32(fs.Length));
            string s = System.Text.Encoding.Default.GetString(file, 0, file.Length);
            fs.Close();
            return s.Remove(0, 1);
        }
        /// <summary>
        /// 读取文件
        /// </summary>
        /// <param name="Path"></param>
        /// <returns>结果</returns>
        public string _Read(string Path)
        {
            string text = "";
            if (File.Exists(Path))
            {
                using (FileStream fs = File.OpenRead(Path))
                {
                    byte[] file = new Byte[fs.Length];
                    fs.Read(file, 0, file.Length);
                    text = Encoding.UTF8.GetString(file, 0, file.Length);
                }
            }
            return text;
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="path"></param>
        /// <param name="url"></param>
        /// <param name="message"></param>
        public static void Save(string path, string url, string message)
        {
            try
            {
                FileStream fsobj = new FileStream(path, FileMode.Append, FileAccess.Write);
                StreamWriter _sw = new StreamWriter(fsobj, System.Text.UnicodeEncoding.UTF8);
                _sw.Write(url + "\r\n" + message + ":" + DateTime.Now.ToString() + "\r\n\r\n");
                _sw.Close();
                fsobj.Close();
            }
            catch
            {

            }
        }
    }
}
